package com.loyal.loyalerp.basedata.person_predept.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loyal.loyalerp.basedata.department.mapper.DepartmentMapper;
import com.loyal.loyalerp.basedata.person_predept.model.GyPersonPredept;
import com.loyal.loyalerp.basedata.person_predept.model.vo.PredeptVO;
import com.loyal.loyalerp.basedata.person_predept.service.PredeptService;

@Controller
@RequestMapping("person")
public class PredeptController {
    
	
	
	
	@Autowired
	private PredeptService predeptService;
	
	@Autowired
	private DepartmentMapper deptMapper;
	
	@RequestMapping("seejsp")
	public String seejsp() {
		return "HumenResource/Employee/preDept";
	}
	
	@RequestMapping(value="seePredept")
	public @ResponseBody List<PredeptVO> seePredept(String rowid) {
		List<GyPersonPredept> predeptList=predeptService.selectByPersonId(Integer.parseInt(rowid));
		List<PredeptVO> predeptVOList=new ArrayList<PredeptVO>();
		for(GyPersonPredept predept : predeptList) {
			PredeptVO predeptVO=new PredeptVO();
			String deptname=deptMapper.selectDeptnameByPrimaryKey(predept.getDeptid());
			predeptVO.setDeptname(deptname);
			predeptVO.setPredept(predept);
			predeptVOList.add(predeptVO);
		}
		return predeptVOList;
	}
}
